﻿using System;
using System.Reflection;
using log4net;

[assembly: log4net.Config.XmlConfigurator(Watch = true)]

namespace Common
{
    public class Log
    {
        #region Nested type: LogHandler

        public class LogHandler
        {
            //创建静态单实例类
            //public static LogHandler Instance = new LogHandler();

            //记录日志
            //private static readonly ILog Log = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);

            //分登记记录日志
            public static void LogError(String errModule, Exception ex)
            {
                var log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
                if (ex == null)
                {
                    log.Error(errModule);
                }
                else
                {
                    log.Error("-----在:" + errModule + "模块,错误消息:" + ex.Message);
                }
            }

            public static void LogError(String errModule)
            {
                var log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);

                log.Error(errModule);
            }

            public static void LogWarn(String errModule, Exception ex)
            {
                var log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);

                log.Warn("-----在:" + errModule + "模块,错误消息:" + ex.Message);
            }

            public static void LogWarn(String errModule)
            {
                var log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);

                log.Warn(errModule);
            }

            public static void LogInfo(String errModule, Exception ex)
            {
                var log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
                if (ex == null)
                {
                    log.Info(errModule);
                }
                else
                {
                    log.Info("----在:" + errModule + "模块,错误消息:" + ex.Message);
                }
            }

            public static void LogDebug(String errModule, Exception ex)
            {
                var log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);

                log.Debug("-----在:" + errModule + "模块,错误消息:" + ex.Message);
            }
        }

        #endregion
    }
}